package service;

import beans.Book;
import db.BookDao;

import java.util.List;

public class BookService {
//    public boolean login(String account,String password)
//    {
//        UserDAO userDao=new UserDAO();
//        return userDao.valid(account, password);
//    }

    public List<Book> browse(){
        BookDao dao =new BookDao();
        return dao.getAllRecords();
    }//得到所有书籍

    public boolean addBook(Book book)
    {
        BookDao userDao=new BookDao();
        return userDao.insertRecord(book);
    }

    public List<Book> getRecord(String name)
    {
        BookDao userDao=new BookDao();
        return userDao.getRecord(name);
    }

    public Book getRecordOne(int id)
    {
        BookDao userDao=new BookDao();
        return userDao.getRecordOne(id);
    }

    public int delUser(Book user)
    {
        BookDao userDao=new BookDao();
            if(userDao.deleteRecord(user))
                return 1;
            else
                return 2;
    }

    public int editUser(Book user)
    {
        BookDao userDao=new BookDao();
        BookDao userDAObe = new BookDao();
        if(userDao.updateRecord(userDAObe.getRecordOne(user.getBook_id()),user)) {
            return 1;
        }
        return 1;
    }
}
